import { createRouter, createWebHistory } from 'vue-router'
import LoginView from '@/views/LoginView.vue'
import BoxView from '@/views/BoxView.vue'
import HomeView from '@/views/HomeView.vue'
import AIhelpView from '@/views/AIhelpView.vue'
// 网站
import WebAddressView from '@/views/Website/AddressView.vue'
import WebIndexView from '@/views/Website/IndexView.vue'
import WebSwiperView from '@/views/Website/SwiperView.vue'
import WebContentView from '@/views/Website/ContentView.vue'
// 公司
import SquareView from '@/views/Stone/SquareView.vue'
import BuildView from '@/views/Stone/BuildView.vue'
import CodelistView from '@/views/Code/ListView.vue'
// 设计
import DsPictureView from '@/views/Design/PictureView.vue'
// 设置
import UserView from '@/views/Setting/UserView.vue'
import LoginlogView from '@/views/Setting/LoginlogView.vue'
import CtrllogView from '@/views/Setting/CtrllogView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'login',
      component: LoginView,
      meta: {
        title: '登录'
      }
    },
    {
      path: '/index',
      name: 'index',
      component: BoxView,
      redirect:'/home',
      children: [
        //   控制面板
        {
          path: '/home',
          name: 'home',
          component: HomeView,
          meta: {
            title: '控制面板'
          },
        },
        //   AI助手
        {
          path: '/aihelp',
          name: 'aihelp',
          component: AIhelpView,
          meta: {
            title: 'AI助手'
          },
        },
        //   网站
        {
          path: '/website',
          name: 'website',
          component: WebIndexView,
          meta: {
            title: '网站'
          },

        },
        {
          path: '/website/address',
          name: 'website_address',
          component: WebAddressView,
          meta: {
            title: '公司地址'
          },
        },
        {
          path: '/website/swiper',
          name: 'website_swiper',
          component: WebSwiperView,
          meta: {
            title: '网站轮播图'
          },
        },
        {
          path: '/content',
          name: 'content',
          component: WebContentView,
          meta: {
            title: '内容审核'
          },
        },
        //   公司
        {
          path: '/stone/square',
          name: 'stone_square',
          component: SquareView,
          meta: {
            title: '方料进度'
          },
        },
        {
          path: '/stone/build',
          name: 'stone_build',
          component: BuildView,
          meta: {
            title: '开单模板'
          },
        },
        {
          path: '/code/list',
          name: 'code_list',
          component: CodelistView,
          meta: {
            title: '码单查询'
          },
        },
        //   设计
        {
          path: '/picture',
          name: 'picture',
          component: DsPictureView,
          meta: {
            title: '图片库'
          },
        },
        //   设置
        {
          path: '/user/power',
          name: 'user_power',
          component: UserView,
          meta: {
            title: '用户权限'
          },
        },
        {
          path: '/loginlog',
          name: 'loginlog',
          component: LoginlogView,
          meta: {
            title: '登录日志'
          },
        },
        {
          path: '/ctrllog',
          name: 'ctrllog',
          component: CtrllogView,
          meta: {
            title: '操作日志'
          },
        },
      ],
    },
    {
      path: '/:pathMatch(.*)*',
      name: '404',
      component: () => import('../views/NotFound.vue')
    }
  ],
})
// 路由守卫
router.beforeEach((to, from) => {
  const isAuth = sessionStorage.getItem('Authorization')? true : false;
  // 未登录或非登录界面
  if(to.name!='login' && to.name!= '404' && !isAuth){
      return {name:'login'}
  }
});
export default router
